﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 自动校园网登陆
{
    public class MyButton : Control
    {
        protected bool mouseIn = false;
        private int Style = 0;
        [Category("数据"), Description("Style")]
        public int StyleMy
        {
            get { return Style; }
            set {
                if (value >= 2)
                    Style = 1;
                else if (value < 0)
                    Style = 0;
                else
                    Style = value; 
            }
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            Pen pen = new Pen(Color.Black);
            pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
            pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
            
            if (mouseIn)
            {
                //e.Graphics.DrawRectangle(pen, 0, 0, Width - 1, Height - 1);
                this.BackColor = Color.SteelBlue;
            }
            else
                this.BackColor = Color.LightSkyBlue;
            if (Style == 0)
            {
                e.Graphics.DrawLine(pen, Width / 2 - 5, Height / 2 - 5, Width / 2 + 5, Height / 2 + 5);
                e.Graphics.DrawLine(pen, Width / 2 - 5, Height / 2 + 5, Width / 2 + 5, Height / 2 - 5);
            }
            else
            {
                e.Graphics.DrawLine(pen, Width / 2 - 5, Height / 2, Width / 2 + 5, Height / 2);
            }
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);
            mouseIn = true;
            Graphics g = Graphics.FromHwnd(this.Handle);
            g.Clear(BackColor);
            this.InvokePaint(this, new PaintEventArgs(g, new Rectangle(0, 0, Width, Height)));
        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);
            mouseIn = false;
            Graphics g = Graphics.FromHwnd(this.Handle);
            g.Clear(BackColor);
            this.InvokePaint(this, new PaintEventArgs(g, new Rectangle(0, 0, Width, Height)));
        }
    }
}
